﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CPPEI.Coolzon.Designer.Views
{
    public class SolutionTreeViewNode : INotifyPropertyChanged
    {
        public Guid ID { get; set; }
        public Guid FolderID { get; set; }

        public Guid ParentID { get; set; }

        public string Name
        {
            get;
            set;
        }

        private string _Caption;
        public string Caption
        {
            get
            {
                return _Caption;
            }
            set
            {
                _Caption = value;
                NotifyPropertyChanged();
                NotifyPropertyChanged("ToolTip");
            }
        }

        public string Header
        {
            get
            {
                if (this.NodeType == Views.NodeType.Solution
                    || this.NodeType == Views.NodeType.Folder
                    || this.NodeType == Views.NodeType.Resource || this.NodeType == Views.NodeType.Template)
                {
                    return Name;
                }
                else
                {
                    return Caption;
                }
            }
            set
            {
                if (this.NodeType == Views.NodeType.Solution
                    || this.NodeType == Views.NodeType.Folder
                    || this.NodeType == Views.NodeType.Resource || this.NodeType == Views.NodeType.Template)
                {
                    this.Name = value;
                }
                else
                {
                    this.Caption = value;
                }
                NotifyPropertyChanged();
            }
        }

        public string ToolTip
        {
            get
            {
                return "名称：" + Name;
            }
        }

        private NodeType _nodeType;
        /// <summary>
        /// 节点类型
        /// </summary>
        public NodeType NodeType
        {
            get { return _nodeType; }
            set
            {
                _nodeType = value;
                NotifyPropertyChanged();
            }
        }

        /// <summary>
        /// 是否已修改
        /// </summary>
        public bool Isdirty { get; set; }

        /// <summary>
        /// 是否最新
        /// </summary>
        public bool IsLatest { get; set; }

        private bool _isSelected;
        /// <summary>
        /// 是否选中
        /// </summary>
        public bool IsSelected
        {
            get { return _isSelected; }
            set
            {
                _isSelected = value;
                NotifyPropertyChanged();
            }
        }

        private bool _isExpanded;
        /// <summary>
        /// 是否展开
        /// </summary>
        public bool IsExpanded
        {
            get { return _isExpanded; }
            set
            {
                _isExpanded = value;
                NotifyPropertyChanged();
            }
        }

        private NodeStatus _nodeStatus;
        public NodeStatus NodeStatus
        {
            get { return _nodeStatus; }
            set
            {
                _nodeStatus = value;
                NotifyPropertyChanged();
            }
        }

        private bool _isInEditMode = false;
        public bool IsInEditMode
        {
            get { return _isInEditMode; }
            set
            {
                _isInEditMode = value;
                NotifyPropertyChanged();
            }
        }

        public string LocalPath { get; set; }

        public string Extension { get; set; }

        public object Tag
        {
            get { return _tag; }
            set
            {
                _tag = value;
                NotifyPropertyChanged();
            }
        }

        public ObservableCollection<SolutionTreeViewNode> Children { get; set; }

        public SolutionTreeViewNode()
        {
            Children = new ObservableCollection<SolutionTreeViewNode>();
        }

        public event PropertyChangedEventHandler PropertyChanged;
        private object _tag;
        private void NotifyPropertyChanged([System.Runtime.CompilerServices.CallerMemberName] string propertyName = "")
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        public void UpdateThumbnail()
        {
            NotifyPropertyChanged("ID");
        }
    }
}
